package vn.anhqn.englishsentensetranslator.selectlanguage;

import java.util.ArrayList;
import java.util.List;

import vn.anhqn.englishsentensetranslator.R;
import vn.anhqn.englishsentensetranslator.activity.MainActivity;
import vn.anhqn.englishsentensetranslator.adapter.SelectLanguageAdapter;
import vn.anhqn.englishsentensetranslator.base.fragment.FragmentHaveSlidingMenu;
import vn.anhqn.englishsentensetranslator.constant.ConfigApp;
import vn.anhqn.englishsentensetranslator.onlinetranslate.OnlineTranslateFragment;
import vn.anhqn.englishsentensetranslator.utils.PreferenceHelper;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

public class SelectLanguageFragment extends FragmentHaveSlidingMenu{
	private ListView lvLanguage;
	private Button btnSave;
	private Button btnCancel;
	private SelectLanguageAdapter adapter;
	@Override
	public int getResLayout() {
		return R.layout.select_language_fragment;
	}

	@Override
	public void setBerhaviorView(View mView) {
		lvLanguage = (ListView) mView.findViewById(R.id.lv_language);
		btnSave = (Button) mView.findViewById(R.id.btn_save);
		btnCancel = (Button) mView.findViewById(R.id.btn_cancel);
		
		btnSave.setOnClickListener(this);
		List<String> languages = new ArrayList<String>();
		String [] arrLanguages = getActivity().getResources().getStringArray(R.array.language_arr);
		for (String lang : arrLanguages) {
			languages.add(lang);
		}
		adapter = new SelectLanguageAdapter(languages,getActivity());
		lvLanguage.setAdapter(adapter);
	}

	@Override
	public void onClickView(View v) {
		int id = v.getId();
		switch (id) {
		case R.id.btn_save:
			PreferenceHelper.getInstance(getActivity()).putInt(ConfigApp.PREFERENCES_LANGUAGE_INDEX, adapter.getIndexSelect());
			switchFragment(OnlineTranslateFragment.class);
			((MainActivity)getActivity()).setTextLangSelected();
			break;
		default:
			break;
		}
	}

	@Override
	public int getidTitle() {
		return R.string.select_lang;
	}


}
